package com.shelpe.services.tenant.service.impl;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.shelpe.services.tenant.mongomodel.ForbiddenWord;
import com.shelpe.services.tenant.mongorepository.ForbiddenWordRepository;
import com.shelpe.services.tenant.service.ForbiddenWordService;

@Service
public class ForbiddenWordServiceImpl implements ForbiddenWordService{

	@Autowired
	private ForbiddenWordRepository wordRep;
	
	
	@Override
	public void saveForbiddenWord(ForbiddenWord word) {
		// TODO Auto-generated method stub
		wordRep.save(word);
	}

	@Override
	public void deleteForbiddenWord(ForbiddenWord word) {
		// TODO Auto-generated method stub
		wordRep.delete(word);
	}

	@Override
	public ForbiddenWord getForbiddenWord(String word) {
		// TODO Auto-generated method stub
		return wordRep.findOne(word);
	}
	
	@Override
	public List<ForbiddenWord> getAllForbiddenWords(){
		
		Iterable<ForbiddenWord> item = wordRep.findAll();
		List<ForbiddenWord> res = new ArrayList<ForbiddenWord>();
		
		if(item != null){
			Iterator<ForbiddenWord> it = item.iterator();
			while(it.hasNext()){
				res.add(it.next());
			}
		}
		
		return res;
	}
	
	@Override
	public Iterable<ForbiddenWord> getAllForbiddenWordsIter(){
		
		return wordRep.findAll();
	}
	
}
